﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HotelManagement.BLO;
using HotelManagement.DTO;

namespace HotelManagement.Services
{
    public partial class StartedServicesForm : Form
    {
        private BindingSource _bindingSourceStartedServices = null;
        public StartedServicesForm()
        {
            InitializeComponent();
            Init();
        }

        public void Init()
        {
            _bindingSourceStartedServices = new BindingSource();
            
            RefreshTable();
            InitialGridView();
        }

        private void InitialGridView()
        {
            try
            {;

                //Thêm vào cột edit khách hàng
                DataGridViewButtonColumn edit = new DataGridViewButtonColumn();
                edit.Text = "Select";
                edit.Name = "SelectColumn";
                edit.UseColumnTextForButtonValue = true;
                edit.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                edit.HeaderText = "Chọn";
                edit.CellTemplate.Style.BackColor = Color.Honeydew;
                edit.FlatStyle = FlatStyle.Popup;
                this.dataGridViewStartedServices.Columns.Insert(0, edit);

                dataGridViewStartedServices.Columns["BillDetailID"].HeaderText = "Mã BD";
                dataGridViewStartedServices.Columns["BillID"].HeaderText = "Mã Bill";
                dataGridViewStartedServices.Columns["ServiceID"].HeaderText = "Dịch Vụ";
                dataGridViewStartedServices.Columns["ServiceName"].HeaderText = "Dịch Vụ";
                dataGridViewStartedServices.Columns["CustomerID"].HeaderText = "Mã khách";
                dataGridViewStartedServices.Columns["StartDate"].HeaderText = "Bắt đầu";
                dataGridViewStartedServices.Columns["EndDate"].HeaderText = "Kết thúc";
                dataGridViewStartedServices.Columns["Cost"].HeaderText = "Chi phí";
                dataGridViewStartedServices.Columns["Name"].HeaderText = "Họ Tên";
                dataGridViewStartedServices.Columns["IDNo"].HeaderText = "CMND";

                for (int i = 0; i < dataGridViewStartedServices.Columns.Count; i++)
                {
                    if (i > 2)
                    {
                        dataGridViewStartedServices.Columns[i].ReadOnly = true;
                    }
                }
            }
            catch (System.Exception ea)
            {

            }
        }
        private void RefreshTable()
        {
            BillDetailBLO bloRD = new BillDetailBLO();
            _bindingSourceStartedServices.DataSource = bloRD.SelectAllStartedServices();
            _bindingSourceStartedServices.Filter = "";
            this.dataGridViewStartedServices.DataSource = _bindingSourceStartedServices;
        }

        private void dataGridViewStartedServices_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = new DataGridViewRow();
            try
            {
                row = this.dataGridViewStartedServices.Rows[e.RowIndex];
                string colN = dataGridViewStartedServices.Columns[e.ColumnIndex].Name;
                if (colN == "SelectColumn")
                {
                    ServiceManagement._customer.CustomerID = int.Parse(row.Cells["CustomerID"].Value.ToString());
                    ServiceManagement._customer.Name = row.Cells["Name"].Value.ToString();
                    ServiceManagement._customer.IDNo_Passport = row.Cells["IDNo"].Value.ToString();

                    ServiceManagement._billDetail.PaperDetailID = int.Parse(row.Cells["billdetailid"].Value.ToString());
                    ServiceManagement._billDetail.PaperID = int.Parse(row.Cells["billid"].Value.ToString());
                    ServiceManagement._billDetail.ServiceID = int.Parse(row.Cells["serviceid"].Value.ToString());
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (System.Exception el)
            {
                this.DialogResult = DialogResult.Cancel;
                return;
            }
        }
    }
}
